package com.xinhe.web.reposity;

import com.xinhe.web.entity.OrderItem;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public interface OrderItemRepository  extends JpaRepository<OrderItem, Long> {
    @Query(value = "select * from tb_order_item where removed=0 and f_order_id=?1", nativeQuery = true)
    List<OrderItem> findByOrderId(Long id);

    @Modifying
    @Query(value = "update tb_order_item set status = ?2 where removed = 0 and f_order_id =?1", nativeQuery = true)
    void updateStatusByOrderId(Long id, String payed);
    @Query(value = "select * from tb_order_item where removed=0 and f_order_id in ?1", nativeQuery = true)
    List<OrderItem> findListByOrderIds(Set<Long> orderIds);
    @Query(value = "select * from tb_order_item where removed=0 and f_user_id=?1 and status=?2 and f_goods_price_id=?3", nativeQuery = true)
    OrderItem findByUserIdAndGoodsPriceIdAndStatus(Long userId, Long goodsPriceId, String status);
    @Modifying
    @Query(value = "update tb_order_item set status = ?2 where removed = 0 and id = ?1", nativeQuery = true)
    void updateStatusByOrderItemId(Long id, String service_apply);
    @Query(value = "select count(1) from tb_order_item where removed = 0 and status in ?2 and f_order_id = ?1", nativeQuery = true)
    Integer countByOrderIdAndStatues(Long orderId, HashSet hashSet);
}
